package com.tucc.hello.leetcode.no1_400.no1_200.no1_20.no11_20.no13;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author tucc
 * @description todo
 * @package com.tucc.hello.leetcode
 * @date 2021/5/20
 **/
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.romanToInt("MCMXCIV"));
    }

    /**
     * @param s
     * @return
     */
    public int romanToInt(String s) {
        Map<Character, Integer> charMap = new HashMap<>();
        {
            char[] chars = {'I','V','X','L','C','D','M'};
            int[] nums = {1, 5, 10, 50, 100, 500, 1000};
            for(int i = 0;i < chars.length; i ++){
                charMap.put(chars[i], nums[i]);
            }
        }
        int sum = 0;
        int max = 0;
        for(int i = s.length() - 1; i >= 0; i --){
            int curVal = charMap.get(s.charAt(i));
            if(curVal < max){
                sum -= curVal;
            }
            else{
                sum += curVal;
                max = curVal;
            }
        }
        return sum;
    }



}
